﻿<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8" />
    <title>学生信息转移</title>
    <link href="../../../css/main.css" rel="stylesheet" type="text/css">
    <link href="../../../layer_v2.1/layer/skin/layer.css" rel="stylesheet" type="text/css">
    <link href="../../../bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="../../../bstable/css/bootstrap-table.css" rel="stylesheet" type="text/css">
    <style>
        input[name="btSelectAll"] {
            position: relative;
            bottom: 7px;
        }
        input[name="btSelectAll"]::after{
            content: '全选';
            color: #000;
            position: relative;
            left: 15px;
            bottom: 3px;
        }
        .bootstrap-table {
            padding: 20px;
        }
    </style>
</head>

<body>
    <div class="tabe_div">
        <p class="p_line text_ient">
            <a class="find_a">新老师手机号：</a>
            <input id="phone" maxlength="11" type="text" class="form_input text_ient" placeholder="输入手机号" />
            <a class="find_a">新招生老师姓名：</a>
            <input id="name" maxlength="10" type="text" class="form_input text_ient" placeholder="输入名称" />
            <input type="button" style="float: right; padding: 10px 50px;" value="转移" class="but_find" id="btn"/>
        </p>
        <table data-url="json/data_alae_list.json" id="table" class="table_style" style="margin: 0px auto">
        </table>

    </div>
    <div></div>
    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../js/date/js/laydate.js"></script>
    <script src="../../../layer_v2.1/layer/layer.js"></script>
    <script src="../../../bstable/js/bootstrap.min.js"></script>
    <script src="../../../bstable/js/bootstrap-table.js"></script>
    <script src="../../../bstable/js/bootstrap-table-zh-CN.min.js"></script>

    <script type="text/javascript">
        localStorage.setItem('name', '学生管理/学生信息转移')
        $(function () {
            var teacherId = ''
            $('#btn').on('click', function() {
                var rows = $("#table").bootstrapTable('getSelections')
                var ids = []
                if(!rows.length) {
                    return alert('请至少选择一项')
                }
                if(!teacherId) {
                    return alert('未找到老师')
                }
                rows.forEach(function(item) {
                    ids.push(item.id)
                })
                $.ajax({
                    url: baseUrl + "studentInfo/studentChange",
                    method: "post",
                    headers: {
                        "Authorization": JSON.parse(localStorage.getItem('userInfo')).token
                    },
                    data: {
                        teacherId: teacherId,
                        studentIds: ids.join(',')
                    },
                    success: function (data) {
                        alert('转移成功')
                        $('#table').bootstrapTable("refresh");
                    }
                })
            })
            $('#phone').on('blur', function() {
                var val = $(this).val()
                if(!val) return
                $.ajax({
                    url: baseUrl + "studentInfo/getTeacherNameByMobile",
                    method: "get",
                    headers: {
                        "Authorization": JSON.parse(localStorage.getItem('userInfo')).token
                    },
                    data: {
                        mobile: val
                    },
                    success: function (data) {
                        if(data.name) {
                            $('#name').val(data.name)
                            teacherId = data.id
                        }
                    }
                })
            })
            $('#table')
                .bootstrapTable({
                    method: "get",
                    striped: true,
                    singleSelect: false,
                    url: baseUrl + 'studentInfo/getStudentAllInfo',
                    dataType: "json",
                    pagination: true, //分页
                    sidePagination:"server",
                    pageSize: 10,
                    pageNumber: 1,
                    search: false, //显示搜索框
                    contentType: "application/x-www-form-urlencoded",
                    ajaxOptions:{
                        headers: {"Authorization": JSON.parse(localStorage.getItem('userInfo')).token}
                    },
                    queryParams: function(params) {
                        params.offset = params.offset / params.limit
                        return params
                    },
                    responseHandler: function(res) {
                        console.log(res)
                        var list = res.data.result.records
                        list.forEach(function(item,i ) {
                            !item && (list[i] = {})
                        })
                        console.log(list)
                        return {
                            rows: list,
                            total: res.data.total
                        }
                    },
                    checkbox: true,
                    columns: [
                        {
                            checkbox: true,
                            width: 80
                        },
                        {
                            field: 'no',
                            title: '序号',
                            sortable: true,
                            align: "center",
                            width: 100,
                            formatter: function (value, row, index) {
                                var pageSize=$('#table').bootstrapTable('getOptions').pageSize;
                                var pageNumber=$('#table').bootstrapTable('getOptions').pageNumber;
                                return pageSize * (pageNumber - 1) + index + 1;
                            }
                        },
                        {
                            title: '学生姓名',
                            field: 'name',
                            align: 'center',
                            valign: 'middle'
                        },
                        {
                            title: '身份证号',
                            field: 'idNo',
                            align: 'center'
                        },
                        {
                            title: '招生老师手机号',
                            field: 'teacherMobile',
                            align: 'center',
                            width: 300,
                        }
                    ]
                });
        });

    </script>
</body>

</html>